import { ImagePreviewGroup, Image } from '@arco-design/web-vue'
import emptyImg from './empty.png'

export default function PreviewImg(value: any) {
  const size = value.size || 80
  const imgValue = value.value
  const title = value.title

  // 空
  if (imgValue == null) {
    return <Image src={emptyImg} width={size} height={size} preview={false} />
  }
  // 单张
  if (Array.isArray(imgValue) == false) {
    const singleUrl = `${import.meta.env.VITE_BASE_PATH}/uploadFile/image/${imgValue}`
    return <Image title={title} src={singleUrl} width={size} height={size} class="cursor-pointer" />
  }

  const urlList = imgValue.map((item: string) => {
    return `${import.meta.env.VITE_BASE_PATH}/uploadFile/image/${item}`
  })

  return (
    <ImagePreviewGroup infinite>
      <a-space wrap>
        {urlList.map((it: string) => {
          return <Image src={it} width={size} height={size} alt="图片损坏" />
        })}
      </a-space>
    </ImagePreviewGroup>
  )
}
